<?php

/**
 * category actions.
 *
 * @package    tsantek-shop
 * @subpackage category
 * @author     Tomislav Šantek
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class categoryActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->forward('category', 'show');
  }

  public function executeShow(sfWebRequest $request)
  {
      // Display all products in this category

      $slug = $request->getParameter('slug');
      if($slug == null)
          $this->redirect ($this->generateUrl ('homepage'));

      $this->forward404Unless($cat = Doctrine_core::getTable('Category')->findOneBySlug($slug));

      $maxPerPage = sfconfig::get('app_Category_maxPerPage', 12);
      $page = $request->getParameter('page', 1);

      $this->pager = new sfDoctrinePager('Product', $maxPerPage);
      $this->pager->setQuery(ProductTable::getByCategoryQuery($cat->getId()));
      $this->pager->setPage($page);

      if($this->pager->getLastPage() > $page)
        $this->redirect ($this->generateUrl ('category_show', array('page'=>1)));

      $this->pager->init();

//      $cat instanceof Category;
//
//      $this->products = Doctrine_core::getTable('Product')->findByCategoryId($cat->getId());

  }
}
